{% extends 'base/base.html' %}
{% load static %}

{% block title %}
Scan history
{% endblock title %}

{% block custom_js_css_link %}
<link rel="stylesheet" type="text/css" href="{% static 'plugins/table/datatable/datatables.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'assets/css/forms/theme-checkbox-radio.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'plugins/table/datatable/dt-global_style.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'plugins/table/datatable/custom_dt_custom.css' %}">
<script src="{% static 'plugins/sweetalerts/promise-polyfill.js' %}"></script>
<link href="{% static 'plugins/sweetalerts/sweetalert2.min.css' %}" rel="stylesheet" type="text/css" />
<link href="{% static 'plugins/sweetalerts/sweetalert.css' %}" rel="stylesheet" type="text/css" />
<link href="{% static 'assets/css/components/custom-sweetalert.css' %}" rel="stylesheet" type="text/css" />
<link href="{% static 'assets/css/components/custom-modal.css' %}" rel="stylesheet" type="text/css" />
{% endblock custom_js_css_link %}

{% block breadcrumb_title %}
Scan History
{% endblock breadcrumb_title %}

{% block main_content %}
<div class="col-lg-12 layout-spacing">
    <div class="col-lg-12">
        <div class="statbox widget box box-shadow">
            <div class="widget-header">
                <div class="row">
                    <div class="col-xl-12 col-md-12 col-sm-12 col-12">
                        <h4>Scan History</h4>
                    </div>
                </div>
            </div>
            <div class="widget-content widget-content-area">
                <div class="table-responsive mb-4">
                    <table id="style-2" class="table style-2  table-hover">
                        <thead>
                            <tr>
                                <th>Serial</th>
                                <th>Domain Name</th>
                                <th>Scan Type</th>
                                <th>Last Scanned On</th>
                                <th class="text-center">Status</th>
                                <th class="text-center">Result</th>
                                <th class="text-center">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for scan_history in scan_history.all %}
                            <tr>
                                <td class="checkbox-column"> {{ scan_history.id }} </td>
                                <td>{{ scan_history.domain_name }}</td>
                                <td>{{ scan_history.scan_type }}</td>
                                <td>{{ scan_history.last_scan_date }}</td>
                                <td class="text-center">
                                    {% if scan_history.scan_status == -1 %}
                                    <span class="shadow-none badge badge-warning bs-tooltip" data-placement="top" title="Waiting for other scans to complete">{% include 'base/_items/progress_spin.html' %}Pending</span>
                                    {% elif scan_history.scan_status == 0 %}
                                    <span class="shadow-none badge badge-danger">Failed</span>
                                    {% elif scan_history.scan_status == 1 %}
                                    <span class="shadow-none badge badge-primary">{% include 'base/_items/progress_spin.html' %}Scanning</span>
                                    {% elif scan_history.scan_status == 2 %}
                                    <span class="shadow-none badge badge-success p-2">Succesful</span>
                                    {% elif scan_history.scan_status == 3 %}
                                    <span class="shadow-none badge badge-danger">Aborted</span>
                                    {% else %}
                                    <span class="shadow-none badge badge-danger">Unknown</span>
                                    {% endif %}
                                </td>
                                <td class="text-center">
                                    <a href="{% url 'detail_scan' scan_history.id %}" class="btn btn-outline-primary">View</a>
                                </td>
                                <td class="text-center">
                                    {% if scan_history.scan_status == 1 or scan_history.scan_status == -1%}
                                    <a onclick="stop_scan('{{ scan_history.celery_id }}')" href="#" class="bs-tooltip" data-toggle="tooltip" data-placement="top" title="" data-original-title="Stop Scan">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather table-delete feather-alert-octagon"><polygon points="7.86 2 16.14 2 22 7.86 22 16.14 16.14 22 7.86 22 2 16.14 2 7.86 7.86 2"></polygon><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>
                                    </a>
                                    {% endif %}
                                    <a onclick="delete_scan({{ scan_history.id }})" href="#" class="bs-tooltip" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete Scan {{ scan_history.domain_name }}">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather table-delete feather-x-circle">
                                            <circle cx="12" cy="12" r="10"></circle>
                                            <line x1="15" y1="9" x2="9" y2="15"></line>
                                            <line x1="9" y1="9" x2="15" y2="15"></line>
                                        </svg>
                                    </a>

                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock main_content %}


{% block page_level_script %}
<script src="{% static 'custom/custom.js' %}"></script>
<script src="{% static 'startScan/js/custom_start_scan.js' %}"></script>
<script src="{% static 'plugins/table/datatable/datatables.js' %}"></script>
<script src="{% static 'plugins/sweetalerts/sweetalert2.min.js' %}"></script>
<script src="{% static 'plugins/sweetalerts/custom-sweetalert.js' %}"></script>
<script>
// var e;
c1 = $('#style-2').DataTable({
    headerCallback:function(e, a, t, n, s) {
        e.getElementsByTagName("th")[0].innerHTML='<label class="new-control new-checkbox checkbox-outline-info m-auto">\n<input type="checkbox" class="new-control-input chk-parent select-customers-info" id="customer-all-info">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span>\n</label>'
    },
    columnDefs:[ {
        targets:0, width:"30px", className:"", orderable:!1, render:function(e, a, t, n) {
            return'<label class="new-control new-checkbox checkbox-outline-info  m-auto">\n<input type="checkbox" class="new-control-input child-chk select-customers-info" id="customer-all-info">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span>\n</label>'
        }
    }],
    "oLanguage": {
        "oPaginate": { "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>', "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>' },
        "sInfo": "Showing page _PAGE_ of _PAGES_",
        "sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
        "sSearchPlaceholder": "Search...",
        "sLengthMenu": "Results :  _MENU_",
    },
    "lengthMenu": [5, 10, 20, 30, 50, 100],
    "pageLength": 10
});
multiCheck(c1);
</script>
{% endblock page_level_script %}
